package com.jacky.dubbo3.controller;


import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.jacky.dubbo3.api.IUserService;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "user")
public class UserController {

    @DubboReference(check = false)
    private IUserService userService;

    /**
     * 这里设备的dubbo.tag是在TagStateRouter里进行判断解析的
     *
     * @param req
     * @return
     */
    @GetMapping(value = "userInfo")
    public String getUserInfo(HttpServletRequest req) {
        String grayHeader = req.getHeader("gray.tag");
        if (StringUtils.isNotBlank(grayHeader)) {
            RpcContext.getClientAttachment().setAttachment("dubbo.tag", grayHeader);
        }
        return userService.getUserInfo();
    }
}
